package com.dingyx.ps.util;


import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;
import java.util.Collections;

/**
 * api公共类
 * @author dingyuxin
 */
public class ApiUtil {

    /**
     * 生成加密后的签名
     * @param nonce
     * @param timestamp
     * @param key
     * @return
     */
    public static String sortAndEncrypt(String nonce,String timestamp,String key) {
        ArrayList<String> list = new ArrayList<String>();
        list.add(nonce);
        list.add(timestamp);
        list.add(key);
        Collections.sort(list);
        return DigestUtils.shaHex(list.get(0) + list.get(1)+list.get(2));
    }

    /**
     * 生成一个三位的随机数
     * @return
     */
    public static  String rundom3(){
        String nonce = "";
        for (int i = 0; i < 3; i++) {
            nonce += String.valueOf((int) (Math.random() * 10));
        }
        return nonce;
    }



}